var register_popup = null
var register_form_sending = false

function registerShow()
{
	register_popup = new Popup(310, 360);
	register_popup.show()
	ajax.sendAsync("./action/user/register.php5?action=show&u="+new Date().getTime(), function(datas)
	{
		ajax.eval(datas)
	})
}
function registerInit()
{
	userEvalPassword('register')
	userEvalLanguage('register')
	
	document.getElementById("register_saisie_login").onblur = function(e)
	{
		registerShowError()
	}
	document.getElementById("register_saisie_login").onchange
	document.getElementById("register_saisie_login").onkeyup = function(e)
	{
		registerCheckUser()
	}
	document.getElementById("register_saisie_password").onchange
	document.getElementById("register_saisie_password").onkeyup = function(e)
	{
		userEvalPassword('register');
		userCheckPassword('register')
	}
	document.getElementById("register_saisie_confirm").onchange
	document.getElementById("register_saisie_confirm").onkeyup = function(e)
	{
		userCheckPassword('register')
	}
	document.getElementById("register_saisie_country").onclick = function(e)
	{
		if(window.event)
		{
			target = window.event.srcElement
		}
		else
		{
			target = e.target
		}
		while(target.tagName != "LI" && target != null && target.getAttribute("fc_id")==null)
		{
			target = target.parentNode;
		}
		if(target==null || target.getAttribute("fc_id")==null)
		{
			return
		}
		document.getElementById("register_saisie_language").value = target.getAttribute("fc_id")
		userEvalLanguage('register')
	}
	try
	{
		document.getElementById("register_saisie_login").focus()
	}
	catch(e){}
}

var register_to = 0
function registerCheckUser()
{
	clearTimeout(register_to)
	register_to = setTimeout(function ()
	{
		var login = document.getElementById('register_saisie_login').value
		if(login=='')
		{
			document.getElementById('register_saisie_login').removeAttribute("validity")
			registerHideError();
		}
		else
			{
			var datas = new Array();
			datas['login'] = login

			ajax.sendAsync("./action/user/register.php5?action=checkUser&u="+new Date().getTime(), function(datas)
			{
				ajax.eval(datas)
				document.getElementById('register_saisie_login').setAttribute("validity", result_validity)
				if(result_validity)
				{
					registerHideError();
				}
			}, datas)
		}
	}, 500)
}

var registerError_shown = false
function registerError(message, show)
{
	if(show==null) show = false
	document.getElementById("register_warning").innerHTML = message
	if(show || registerError_shown)
	{
		registerShowError()
	}
}
function registerShowError()
{
	registerError_shown = true;
	if(document.getElementById("register_warning").innerHTML != "")
	{
		document.getElementById("register_warning_icon").style.visibility="visible"
	}
}
function registerHideError()
{
	registerError_shown = false;
	document.getElementById("register_warning").innerHTML=""
	document.getElementById("register_warning_icon").style.visibility="hidden"
}

function registerSent()
{
	var register_form = document.getElementById("register_form");
	disabledForm(register_form, true)

	ajax.sendAsync("./action/user/register.php5?action=save&u="+new Date().getTime(), function(datas)
	{
		ajax.eval(datas);
		if(result_validity==0)
		{
			registerShowError()
		}
		else
		{
			registerHideError()
		}
		
		disabledForm(register_form, false)
	}, ajax.buildDatas(register_form))
}